package seotools.positions;

import obj.Accum;
import obj.Charger;
import util.Helper;

import java.io.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Extramobi2 {
    public static int counter = 0;

    public static final String NA = "уточняйте";
    public static final int COLUMNS = 8;

    public static StringBuilder header;

    public static void main(String[] args) throws IOException {
        header = readHeaderProps();
        Map<String, String> props = readProps("accums.properties");
        String cat = "data/accums/";
        printAccums("accums.nokia", "Nokia", 1.25, props, true, cat + "extramobi-accums-nokia-price", false);
        printAccums("accums.nokiamaxcell", "NokiaMaxcell", 1, props, false, cat + "extramobi-accums-nokia-maxcell-price", false);
        printAccums("accums.se", "Sony Ericsson", 1, props, true, cat + "extramobi-accums-se-price", false);
        printAccums("accums.samsung", "Samsung", 1, props, true, cat + "extramobi-accums-samsung-price", true);
        printAccums("accums.lg", "LG", 1, props, false, cat + "extramobi-accums-lg-price", false);
        printAccums("accums.motorola", "Motorola", 1, props, false, cat + "extramobi-accums-motorola-price", false);
        printAccums("accums.htc", "HTC", 1, props, true, cat + "extramobi-accums-htc-price", false);
        props = readProps("chargers.properties");
        PrintStream out = new PrintStream(new FileOutputStream("extramobi-rest-price.txt"));
        out.println(header);
        printCategory("chargers", props, out);
        printCategory("chargers.network", props, out);
        printChargers("chargers.network", "Nokia", props, out, 5, 1);
        printChargers("chargers.network", "Samsung", props, out, 5, 1);
        printChargers("chargers.network", "Sony Ericsson", props, out, 5, 1);
        printChargers("chargers.network", "LG", props, out, 5, 1);
        printCategory("chargers.auto", props, out);
        printChargers("chargers.auto", "Nokia", props, out, 5, 1);
        printChargers("chargers.auto", "Samsung", props, out, 5, 1);
        printChargers("chargers.auto", "Sony Ericsson", props, out, 5, 1);
        printChargers("chargers.auto", "LG", props, out, 5, 1);
        props = readProps("holders.properties");
        printCategory("holders", props, out);
        props = readProps("cardreaders.properties");
        printCategory("cardreaders", props, out);

//        printOrigChargers();


        out.close();
    }

    private static StringBuilder readHeaderProps() throws IOException {
        BufferedReader reader = new BufferedReader(new FileReader("data/header.properties"));
        StringBuilder sb = new StringBuilder();
        String line;
        while ((line = reader.readLine()) != null) {
            if (line.startsWith("#")) continue;
            String header = line.split("=")[1];
            sb.append(";").append(header);
        }
        sb.delete(0, 1);
        reader.close();
        return sb;
    }

    private static Map<String, String> readProps(String fileName) throws IOException {
        BufferedReader reader;
        String line;
        reader = new BufferedReader(new FileReader("data/" + fileName));
        Map<String, String> accums = new HashMap<String, String>();
        boolean moved = false;
        String lastKey = "";
        while ((line = reader.readLine()) != null) {
            if (line.startsWith("#")) continue;
            if (moved) {
                String value = accums.get(lastKey);
                String newValue = value.replace("\\", line);
                accums.put(lastKey, newValue);
                if (!newValue.endsWith("\\")) {
                    moved = false;
                }
                continue;
            }
            String[] keyvalue = line.split("=");
            String key = keyvalue[0];
            if (keyvalue.length == 1) {
                accums.put(key, "");
            } else {
                String value = keyvalue[1];
                accums.put(key, value);
                if (value.endsWith("\\")) {
                    moved = true;
                    lastKey = key;
                }
            }
        }
        return accums;
    }

    private static void printCategory(String category, Map<String, String> props, PrintStream out) {
        StringBuilder sb = new StringBuilder();
        sb.append(props.get(category + ".name.eng")).append(";").
                append(props.get(category + ".name.rus")).append(";").
                append(props.get(category + ".id")).append(";").
                append(props.get(category + ".price")).append(";").
                append(props.get(category + ".oldprice")).append(";").
                append(props.get(category + ".count")).append(";").
                append(props.get(category + ".desc.eng")).append(";").
                append(props.get(category + ".desc.rus")).append(";").
                append(props.get(category + ".shortdesc.eng")).append(";").
                append(props.get(category + ".shortdesc.rus")).append(";").
                append(counter++).append(";").
                append(props.get(category + ".title.eng")).append(";").
                append(props.get(category + ".title.rus")).append(";").
                append(props.get(category + ".meta.keywords.eng")).append(";").
                append(props.get(category + ".meta.keywords.rus")).append(";").
                append(props.get(category + ".meta.desc.eng")).append(";").
                append(props.get(category + ".meta.desc.rus")).append(";").
                append(props.get(category + ".photo"));
        out.println(sb.toString());
    }

    private static void printAccums(String category, String brandName, double coef, Map<String, String> props, boolean printModels, String outName, boolean split) throws IOException {
        PrintStream out = new PrintStream(new FileOutputStream(outName + ".txt"));
        out.println(header.toString());
        printCategory("accums", props, out);
        printCategory(category.replace("maxcell", ""), props, out);
        String fileName = props.get(category + ".data");
        BufferedReader reader = new BufferedReader(new FileReader(fileName));
        List<Accum> accumsList = new ArrayList<Accum>();
        String line;
        while ((line = reader.readLine()) != null) {
            if (line.contains("﻿")) {
                line = line.replace("﻿", "");
            }
            Accum accum = Accum.parseAccum(line, coef);
            accumsList.add(accum);
        }
        reader.close();
        int count = 0;
        int fileCount = 0;
        for (Accum accum : accumsList) {
            count++;
            if (printModels) {
                accum.modelName = "";
            }
            accum.brandName = brandName;
            StringBuilder sb = new StringBuilder();
            String titleEng = props.get("accums.brand.title.eng");
            String titleRus = props.get("accums.brand.title.rus");
            String descEng = props.get("accums.brand.desc.eng");
            String descRus = props.get("accums.brand.desc.rus");
            String shortDescEng = props.get("accums.brand.shortdesc.eng");
            String shortDescRus = props.get("accums.brand.shortdesc.rus");
            String metaDescEng = props.get("accums.brand.meta.desc.eng");
            String metaDescRus = props.get("accums.brand.meta.desc.rus");
            String metaKeywordsEng = props.get("accums.brand.meta.keywords.eng");
            String metaKeywordsRus = props.get("accums.brand.meta.keywords.rus");
            if (props.get("accums.brand." + brandName.toLowerCase() + ".title.eng") != null) {
                titleEng = props.get("accums.brand." + brandName.toLowerCase() + ".title.eng");
            }
            if (props.get("accums.brand." + brandName.toLowerCase() + ".title.rus") != null) {
                titleRus = props.get("accums.brand." + brandName.toLowerCase() + ".title.rus");
            }
            if (props.get("accums.brand." + brandName.toLowerCase() + ".desc.eng") != null) {
                descEng = props.get("accums.brand." + brandName.toLowerCase() + ".desc.eng");
            }
            if (props.get("accums.brand." + brandName.toLowerCase() + ".desc.rus") != null) {
                descRus = props.get("accums.brand." + brandName.toLowerCase() + ".desc.rus");
            }
            if (props.get("accums.brand." + brandName.toLowerCase() + ".shortdesc.eng") != null) {
                shortDescEng = props.get("accums.brand." + brandName.toLowerCase() + ".shortdesc.eng");
            }
            if (props.get("accums.brand." + brandName.toLowerCase() + ".shortdesc.rus") != null) {
                shortDescRus = props.get("accums.brand." + brandName.toLowerCase() + ".shortdesc.rus");
            }
            if (props.get("accums.brand." + brandName.toLowerCase() + ".meta.desc.eng") != null) {
                metaDescEng = props.get("accums.brand." + brandName.toLowerCase() + ".meta.desc.eng");
            }
            if (props.get("accums.brand." + brandName.toLowerCase() + ".meta.desc.rus") != null) {
                metaDescRus = props.get("accums.brand." + brandName.toLowerCase() + ".meta.desc.rus");
            }
            if (props.get("accums.brand." + brandName.toLowerCase() + ".meta.keywords.eng") != null) {
                metaKeywordsEng = props.get("accums.brand." + brandName.toLowerCase() + ".meta.keywords.eng");
            }
            if (props.get("accums.brand." + brandName.toLowerCase() + ".meta.keywords.rus") != null) {
                metaKeywordsRus = props.get("accums.brand." + brandName.toLowerCase() + ".meta.keywords.rus");
            }
            sb.append(filterAccums(props.get("accums.brand.name.eng"), accum, accumsList)).append(";").
                    append(filterAccums(props.get("accums.brand.name.rus"), accum, accumsList)).append(";").
                    append(filterAccums(props.get("accums.brand.id"), accum, accumsList).replaceAll("\\s", "_")).append(";").
                    append(accum.price).append(";").
                    append(accum.oldPrice).append(";").
                    append(accum.count).append(";").
                    append(filterAccums(descEng, accum, accumsList)).append(";").
                    append(filterAccums(descRus, accum, accumsList)).append(";").
                    append(filterAccums(shortDescEng, accum, accumsList)).append(";").
                    append(filterAccums(shortDescRus, accum, accumsList)).append(";").
                    append(counter++).append(";").
                    append(filterAccums(titleEng, accum, accumsList)).append(";").
                    append(filterAccums(titleRus, accum, accumsList)).append(";").
                    append(filterAccums(metaKeywordsEng, accum, accumsList)).append(";").
                    append(filterAccums(metaKeywordsRus, accum, accumsList)).append(";").
                    append(filterAccums(metaDescEng, accum, accumsList)).append(";").
                    append(filterAccums(metaDescRus, accum, accumsList)).append(";").
                    append(filterAccums(props.get("accums.brand.photo"), accum, accumsList));
            out.println(sb.toString());
        }
        if (printModels) {
            for (Accum accum : accumsList) {
                if (count >= 120 && split) {
                    fileCount++;
                    count = 0;
                    out.close();
                    out = new PrintStream(new FileOutputStream(outName + "-" + fileCount + ".txt"));
                    out.println(header.toString());
                    printCategory("accums", props, out);
                    printCategory(category, props, out);
                }
                accum.brandName = brandName;
                count += printModels(accum, props, accumsList, out);
            }
        }
    }

    private static int printModels(Accum accum, Map<String, String> accums, List<Accum> accumsList, PrintStream out) {
        int count = 0;
        for (String device : accum.devices) {
            count++;
            accum.modelName = accum.brandName + " " + device;
            StringBuilder sb = new StringBuilder();
            String titleEng = accums.get("accums.model.title.eng");
            String titleRus = accums.get("accums.model.title.rus");
            String descEng = accums.get("accums.model.desc.eng");
            String descRus = accums.get("accums.model.desc.rus");
            String shortDescEng = accums.get("accums.model.shortdesc.eng");
            String shortDescRus = accums.get("accums.model.shortdesc.rus");
            String metaDescEng = accums.get("accums.model.meta.desc.eng");
            String metaDescRus = accums.get("accums.model.meta.desc.rus");
            String metaKeywordsEng = accums.get("accums.model.meta.keywords.eng");
            String metaKeywordsRus = accums.get("accums.model.meta.keywords.rus");
            if (accums.get("accums.model." + accum.brandName.toLowerCase() + ".title.eng") != null) {
                titleEng = accums.get("accums.model." + accum.brandName.toLowerCase() + ".title.eng");
            }
            if (accums.get("accums.model." + accum.brandName.toLowerCase() + ".title.rus") != null) {
                titleRus = accums.get("accums.model." + accum.brandName.toLowerCase() + ".title.rus");
            }
            if (accums.get("accums.model." + accum.brandName.toLowerCase() + ".desc.eng") != null) {
                descEng = accums.get("accums.model." + accum.brandName.toLowerCase() + ".desc.eng");
            }
            if (accums.get("accums.model." + accum.brandName.toLowerCase() + ".desc.rus") != null) {
                descRus = accums.get("accums.model." + accum.brandName.toLowerCase() + ".desc.rus");
            }
            if (accums.get("accums.model." + accum.brandName.toLowerCase() + ".shortdesc.eng") != null) {
                shortDescEng = accums.get("accums.model." + accum.brandName.toLowerCase() + ".shortdesc.eng");
            }
            if (accums.get("accums.model." + accum.brandName.toLowerCase() + ".shortdesc.rus") != null) {
                shortDescRus = accums.get("accums.model." + accum.brandName.toLowerCase() + ".shortdesc.rus");
            }
            if (accums.get("accums.model." + accum.brandName.toLowerCase() + ".meta.desc.eng") != null) {
                metaDescEng = accums.get("accums.model." + accum.brandName.toLowerCase() + ".meta.desc.eng");
            }
            if (accums.get("accums.model." + accum.brandName.toLowerCase() + ".meta.desc.rus") != null) {
                metaDescRus = accums.get("accums.model." + accum.brandName.toLowerCase() + ".meta.desc.rus");
            }
            if (accums.get("accums.model." + accum.brandName.toLowerCase() + ".meta.keywords.eng") != null) {
                metaKeywordsEng = accums.get("accums.model." + accum.brandName.toLowerCase() + ".meta.keywords.eng");
            }
            if (accums.get("accums.model." + accum.brandName.toLowerCase() + ".meta.keywords.rus") != null) {
                metaKeywordsRus = accums.get("accums.model." + accum.brandName.toLowerCase() + ".meta.keywords.rus");
            }
            sb.append(filterAccums(accums.get("accums.model.name.eng"), accum, accumsList)).append(";").
                    append(filterAccums(accums.get("accums.model.name.rus"), accum, accumsList)).append(";").
                    append(filterAccums(accums.get("accums.model.id"), accum, accumsList).replaceAll("\\s", "_")).append(";").
                    append(accum.price).append(";").
                    append(accum.oldPrice).append(";").
                    append(accum.count).append(";").
                    append(filterAccums(descEng, accum, accumsList)).append(";").
                    append(filterAccums(descRus, accum, accumsList)).append(";").
                    append(filterAccums(shortDescEng, accum, accumsList)).append(";").
                    append(filterAccums(shortDescRus, accum, accumsList)).append(";").
                    append(counter++).append(";").
                    append(filterAccums(titleEng, accum, accumsList)).append(";").
                    append(filterAccums(titleRus, accum, accumsList)).append(";").
                    append(filterAccums(metaKeywordsEng, accum, accumsList)).append(";").
                    append(filterAccums(metaKeywordsRus, accum, accumsList)).append(";").
                    append(filterAccums(metaDescEng, accum, accumsList)).append(";").
                    append(filterAccums(metaDescRus, accum, accumsList)).append(";").
                    append(filterAccums(accums.get("accums.model.photo"), accum, accumsList));
            out.println(sb.toString());
        }
        return count;
    }

    public static Accum parseAccum(String line, double coef) {
        Accum accum = new Accum();
        String[] fields = line.split(";");
        accum.name = fields[0];
        if (fields.length > 4) {
            accum.vendor = fields[2];
            accum.model = fields[3];
            accum.power = fields[4];
            accum.type = fields[5];
            accum.volt = fields[6];
            accum.price = Integer.valueOf(fields[7]);
            accum.count = Integer.valueOf(fields[8]);
        } else {
            accum.price = Integer.valueOf(fields[2]);
            accum.count = Integer.valueOf(fields[3]);
        }
        accum.devices = fields[1].split(",");
        accum.oldPrice = (int) (accum.price * coef);
        return accum;
    }

    private static void printChargers(String category, String brandName, Map<String, String> props, PrintStream out, int columns, double coef) throws IOException {
        boolean isAuto = category.contains("auto");
        Charger charger = parseCharger(props.get(category + "." + brandName.toLowerCase().replace("sony ericsson", "se") + ".data"), coef, isAuto, brandName);
        StringBuilder sb = new StringBuilder();
        sb.append(filterChargers(category, props, props.get(category + ".brand.name.eng"), charger, columns)).append(";").
                append(filterChargers(category, props, props.get(category + ".brand.name.rus"), charger, columns)).append(";").
                append(filterChargers(category, props, props.get(category + ".brand.id"), charger, columns)).append(";").
                append(charger.price).append(";").
                append(charger.oldPrice).append(";").
                append(charger.count).append(";").
                append(filterChargers(category, props, props.get(category + ".brand.desc.eng"), charger, columns)).append(";").
                append(filterChargers(category, props, props.get(category + ".brand.desc.rus"), charger, columns)).append(";").
                append(filterChargers(category, props, props.get(category + ".brand.shortdesc.eng"), charger, columns)).append(";").
                append(filterChargers(category, props, props.get(category + ".brand.shortdesc.rus"), charger, columns)).append(";").
                append(counter++).append(";").
                append(filterChargers(category, props, props.get(category + ".brand.title.eng"), charger, columns)).append(";").
                append(filterChargers(category, props, props.get(category + ".brand.title.rus"), charger, columns)).append(";").
                append(filterChargers(category, props, props.get(category + ".brand.meta.keywords.eng"), charger, columns)).append(";").
                append(filterChargers(category, props, props.get(category + ".brand.meta.keywords.rus"), charger, columns)).append(";").
                append(filterChargers(category, props, props.get(category + ".brand.meta.desc.eng"), charger, columns)).append(";").
                append(filterChargers(category, props, props.get(category + ".brand.meta.desc.rus"), charger, columns)).append(";").
                append(filterChargers(category, props, props.get(category + ".brand.photo"), charger, columns));
        out.println(sb.toString());

    }

    private static Charger parseCharger(String path, double coef, boolean isAuto, String brandName) throws IOException {
        BufferedReader reader = new BufferedReader(new FileReader(path));
        String[] line = reader.readLine().split(";");
        int price;
        if (isAuto) {
            price = Integer.valueOf(line[2]);
        } else {
            price = Integer.valueOf(line[1]);
        }
        String[] models = line[0].split(",");
        int count = Integer.valueOf(line[3]);
        int oldPrice = (int) (price * coef);
        Charger charger = new Charger();
        charger.brandName = brandName;
        charger.count = count;
        charger.price = price;
        charger.oldPrice = oldPrice;
        charger.models = models;
        return charger;
    }

    private static String filterChargers(String category, Map props, String value, Charger charger, int columns) {
        String result = value.replaceAll("\\$\\{brand\\.name\\}", charger.brandName);
        result = result.replaceAll("\\$\\{brand\\.name\\.url\\}", charger.brandName.replaceAll("\\s", "_").toLowerCase());
        result = result.replaceAll("\\$\\{brand\\.name\\.photo\\}", charger.brandName.replace("Sony Ericsson", "se").toLowerCase());
        result = result.replaceAll("\\$\\{model\\.table\\}", modelsToTable(charger.models, charger.brandName, columns));
        result = result.replaceAll("\\$\\{brand\\.title\\}", (String) props.get(category + "." + charger.brandName.toLowerCase().replace("sony ericsson", "se") + ".title"));
        result = result.replaceAll("\\$\\{brand\\.keywords\\}", (String) props.get(category + "." + charger.brandName.toLowerCase().replace("sony ericsson", "se") + ".keywords"));
        return result;
    }

    public static String modelsToTable(String[] models, String name, int columns) {
        StringBuilder sb = new StringBuilder("<table style=\"font-size:12px\">");
        for (int i = 1; i <= models.length; i++) {
            if (i == 1 && i % columns + 1 == 0) {
                sb.append("<tr>");
            }
            sb.append("<td><strong>").append(name).append(" ").append(models[i - 1]).append("</strong></td>");
            if (i % columns == 0) {
                sb.append("</tr>");
            }
        }
        if (sb.toString().endsWith("</td>")) {
            sb.append("</tr>");
        }
        sb.append("</table>");
        return sb.toString();

    }

    private static String filterAccums(String value, Accum accum, List<Accum> accumsList) {
        String result = value.replaceAll("\\$\\{accum\\.name\\}", accum.name);
        result = result.replaceAll("\\$\\{accum\\.table\\.rus\\}", accumsTableRus(accum, accumsList));
        result = result.replaceAll("\\$\\{accum\\.table\\.eng\\}", accumsTableEng(accum, accumsList));
        result = result.replaceAll("\\$\\{brand\\.name\\}", accum.brandName);
        result = result.replaceAll("\\$\\{model\\.name\\}", accum.modelName);
        result = result.replaceAll("\\$\\{accum\\.name\\.orig\\}", accum.name.replace("Maxcell ", ""));
        result = result.replaceAll("\\$\\{accum\\.name\\.url\\}", accum.name.replaceAll("\\s", "_"));
        result = result.replaceAll("\\$\\{accum\\.name\\.orig\\.url\\}", accum.name.replace("Maxcell ", "").replaceAll("\\s", "_"));
        result = result.replaceAll("\\$\\{brand\\.name\\.translitUrl\\}", Helper.backTranslitUrl(accum.brandName));
        result = result.replaceAll("\\$\\{accum\\.vendor\\}", accum.vendor);
        result = result.replaceAll("\\$\\{accum\\.model\\}", accum.model);
        result = result.replaceAll("\\$\\{accum\\.power\\}", accum.power);
        result = result.replaceAll("\\$\\{accum\\.volt\\}", accum.volt);
        result = result.replaceAll("\\$\\{accum\\.type\\}", accum.type);
        result = result.replaceAll("\\$\\{device\\.titlelist\\}", devicesToTitle(accum.devices));
        result = result.replaceAll("\\$\\{device\\.desclist\\}", devicesToDesc(accum.devices, accum.brandName.replace("Maxcell", "")));
        result = result.replaceAll("\\$\\{device\\.shortlist\\}", devicesToShortDesc(accum.devices));
        result = result.replaceAll("\\$\\{device\\.reflist\\.rus\\}", devicesToRefRus(accum));
        result = result.replaceAll("\\$\\{device\\.reflist\\.eng\\}", devicesToRefEng(accum));
        return result;
    }

    private static String accumsTableRus(Accum accum, List<Accum> accumsList) {
        return accumsTable(accum, accumsList, "Аккумулятор ", "");
    }

    private static String accumsTableEng(Accum accum, List<Accum> accumsList) {
        return accumsTable(accum, accumsList, "Accumulator ", "en/");
    }

    private static String accumsTable(Accum accum, List<Accum> accumsList, String name, String prefix) {
        StringBuilder sb = new StringBuilder("<table style=\"font-size:13px\">");
        int count = 1;
        for (int i = 1; i < accumsList.size(); i++, count++) {
            if (i == 1 || (i % COLUMNS) + 1 == 0) {
                sb.append("<tr>");
            }
            if (accumsList.get(i - 1).equals(accum)) {
                count--;
                continue;
            }
            String accumName = accumsList.get(i - 1).name.toLowerCase().replaceAll("-", " ");
            String accumUrl = ("Accumulator_" + accumsList.get(i - 1).name.replaceAll("\\s", "_")).toLowerCase();
            sb.append("<td style=\"padding:0 20 10 0\"><strong><a href=\"http://extramobi.ru/").append(prefix).append("product/").append(accumUrl).append("\">").append(accumName).append("</a></strong></td>");
            if (count % COLUMNS == 0) {
                sb.append("</tr>");
            }
        }
        if (sb.toString().endsWith("</td>")) {
            sb.append("</tr>");
        }
        sb.append("</table>");
        return sb.toString();
    }

    private static String devicesToRef(Accum accum, String name, String suffix) {
        if (accum.modelName == null) return devicesToDesc(accum.devices, accum.brandName);
        StringBuilder sb = new StringBuilder("<ul>");
        for (String device : accum.devices) {
            String deviceName = name + accum.brandName + " " + device;
            String deviceUrl = accum.brandName.replaceAll("\\s", "_") + "_" + device.replaceAll("\\s", "_");
            if (deviceUrl.equals(accum.modelName.replaceAll("\\s", "_"))) continue;
            sb.append("<li><a href=\"http://extramobi.ru/").append(suffix).append("product/Accumulator_").append(deviceUrl).append("\">").append(deviceName).append("</a></li>");
        }
        sb.append("</ul><br/>");
        return sb.toString();
    }

    private static String devicesToRefRus(Accum accum) {
        return devicesToRef(accum, "Аккумулятор ", "");
    }

    private static String devicesToRefEng(Accum accum) {
        return devicesToRef(accum, "Accumulator ", "en/");
    }


    private static String devicesToTitle(String[] devices) {
        StringBuilder sb = new StringBuilder();
        for (String device : devices) {
            sb.append(" ").append(device);
        }
        sb.delete(0, 1);
        return sb.toString();
    }

    public static String devicesToDesc(String[] devices, String brandName) {
        StringBuilder sb = new StringBuilder("<ul>");
        for (String device : devices) {
            String item = "<li><strong>" + brandName + " " + device + "</strong></li>";
            sb.append(item);
        }
        sb.append("</ul><br/>");
        return sb.toString();
    }


    public static String devicesToShortDesc(String[] devices) {
        StringBuilder sb = new StringBuilder();
        for (String device : devices) {
            sb.append(",<strong>").append(device).append("</strong>");
        }
        sb.deleteCharAt(0);
        return sb.toString();
    }
}

